﻿// JScript 文件
var m_tree = null;
var vMenu = null;
var m_xmlDoc = null;
document.oncontextmenu=function(e){return false;} 
var m_idx = parseInt(window.location.href.split("?")[1]);
function InitAssTree()
{
    CtnTrans.Ajax("/main.ashx?_method=GetAssMainCfg", "POST", "idx=" + m_idx,showTree,null,{loading:true});
}
function showTree(res)
{
    if(!CtnError.validate(res.responseText))
    {
        CtnError.show();
        return;
    };
    m_xmlDoc = CtnXML.getXmlDoc();
    m_xmlDoc.loadXML(res.responseText);
    var root = m_xmlDoc.lastChild;
    m_tree = new CtnTreeCtrl("m_tree", 0, 1);
    m_tree.create("GcdhTree");
    m_tree.onExpand   = onExpand;
    m_tree.onSelectItem = onSelectItem;
    m_tree.onRightMenu  = onRightMenu;
    
    var arr = $XML(root, "str1").split(",");
    m_tree.insertItem($XML(root, "name"),{method:arr[0], nodeMc:arr[1]});
    m_tree.show();
}
function onExpand(item)
{
    if(item.isdeal == false) 
    {
        if (item.data.method == "GCBH" || item.data.method == "JZBM")//到底
        {
            item.show();
            return;
        }
        item.loading();
        CtnTrans.Ajax("/main.ashx?", "post",  "_method=" + encodeURIComponent(item.data.method)+"&node=" + encodeURIComponent(item.data.nodeMc),
        function (res, item)
        {
            item.unloading();
            var xmlInfo = res.responseText;
            if (!CtnError.validate(xmlInfo))
            {
                CtnError.show();
                return;
            }
            else if (xmlInfo != "")
            {
                item.insertXml(xmlInfo);
            }
            item.show();
        },
        item
        ); 
    }     
}

function onSelectItem(item)
{
    if (item.data.method != "GCBH" && item.data.method != "JZBM")//到底
    {
        return;
    }
    var objWnd = top.m_doc.getCurWnd("main");
    if (!objWnd || !checkAssetId(objWnd.tool.id))
    {
        CtnDlg.msg("请将固定资产页面设为当前！");
        return ;
    }
    var tool = {};
    for (var k in objWnd.tool)
    {
        tool[k] = objWnd.tool[k];
    }
    tool.url = "Asset/AssetMain.aspx?idx=" + tool.id + "&bmlx=" + item.data.method + "&bm=" + item.data.BM;
    objWnd.update(tool);
}
//右键菜单
function onRightMenu(item, evt)
{
    if (m_idx == m_vt.ASS_GCDH && item.data.method == "GCBH")
    {
        vMenu = new CtnMenuCtrl("vMenu");
        var nodes = m_xmlDoc.selectNodes("i/i");
        for (var i = 0; i < nodes.length; i++)
        {
            vMenu.addEvent($XML(nodes[i],"name"), "AssetDp(" + i + ");");
        }        
        vMenu.show(evt);
    }
}
function AssetDp(i)
{
    var nodes = m_xmlDoc.selectNodes("i/i");
    AssExeTool($XML(nodes[i],"idx"), nodes[i]);
}
function checkAssetId(id)
{
    switch (id)
    {
        case m_vt.ASS_GCZGGL:
        case m_vt.ASS_ZCXZGL:
        case m_vt.ASS_ZCBFGL:
        case m_vt.ASS_ZCDBGL:
        case m_vt.ASS_ZCXSGL:
        case m_vt.ASS_ZCCZGL:
        case m_vt.ASS_ZCJZGL:
        case m_vt.ASS_ZCJZGL:
        case m_vt.ASS_ZCSYGL:
        case m_vt.ASS_ZCKPGL:return true;
        default:return false;
    }
}